-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSolution.c
42 lines (36 loc) · 1001 Bytes
/
Solution.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include <stdio.h>
void findIntersection(int arr1[], int size1, int arr2[], int size2) {
int i = 0, j = 0;
printf("Intersection of the two arrays: ");
while (i < size1 && j < size2) {
if (arr1[i] < arr2[j]) {
i++;
} else if (arr1[i] > arr2[j]) {
j++;
} else {
printf("%d ", arr1[i]);
i++;
j++;
}
}
printf("\n");
}
int main() {
int size1, size2;
printf("Enter the size of the first array: ");
scanf("%d", &size1);
int arr1[size1];
printf("Enter the elements of the first sorted array: ");
for (int i = 0; i < size1; i++) {
scanf("%d", &arr1[i]);
}
printf("Enter the size of the second array: ");
scanf("%d", &size2);
int arr2[size2];
printf("Enter the elements of the second sorted array: ");
for (int i = 0; i < size2; i++) {
scanf("%d", &arr2[i]);
}
findIntersection(arr1, size1, arr2, size2);
return 0;
}